<template>
	<view class="container container02">
		<!--头部start-->
		<view class="header">
			<u-status-bar></u-status-bar>
			<view class="index_header">
				<text :class="navIndex==0?'on':''" @click="checkIndex(0)">留言</text>
				<text :class="navIndex==1?'on':''" @click="checkIndex(1)">我的留言</text>
				<text :class="navIndex==2?'on':''" @click="checkIndex(2)">申诉记录</text>
				<image src="/static/images/img_31.png" mode="widthFix" class="h_close_img"></image>
			</view>
		</view>
		<u-status-bar></u-status-bar>
		<!--头部end-->
		
		<!--留言start-->
		<view v-show="navIndex==0">
			<view class="message">
				<view class="type_choose">
					<w-radio-picker placeholder="选择分类" :options="optionsList" color="#8B8B8C"  />
				</view>
				
				<view class="textareas">
					<u--textarea placeholder="输入内容......"></u--textarea>
				</view>
				
				<view class="img_list">
					<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1"  multiple :maxCount="10"></u-upload>
				</view>
				
				<view class="m_check">
					<u-checkbox-group>
						<u-checkbox  activeColor="#332C2B" labelSize="30rpx" labelColor="#332C2B" checked></u-checkbox>
					</u-checkbox-group>
					<text>请认真检查所描述的内容后再提交，如果留言涉及投诉内容的，请务必保证实事求是，以避免您的留言被定性为恶意行为。</text>
				</view>
			</view>
			
			<view class="f_btn">
				<button class="submit on">提交</button>
				<u-safe-bottom></u-safe-bottom>
			</view>
		</view>
		<!--留言end-->
		
		<!--我的留言start-->
		<view v-show="navIndex==1">
			<message></message>
		</view>
		<!--我的留言end-->
		
		<!--申诉记录start-->
		<view v-show="navIndex==2">
			<cpRecord></cpRecord>
		</view>
		<!--申诉记录end-->
		
	</view>
</template>

<script>
import message from "../my/message_my.vue";
import cpRecord from "../my/complaint_record.vue";
	
export default{
	components: {
	    /***** mescroll S *****/
	    //注册组件
	    message,cpRecord
	    /***** mescroll E *****/
	},
	data() {
			return {
				fileList1: [{
					url:'/static/images/img_01.jpg'
				}],
				optionsList: [{
					id: 11,
					name: "选项11",
				}, {
					id: 22,
					name: "选项22"
				}],
				navIndex: 0,
			}
		},
		methods:{
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
			checkIndex(index) {
				console.log(index)
				this.navIndex = index;
			},
		}
	
	}  
</script>

<style lang="scss">
	@import url("../../common/style.scss");
	@import url("my.scss");
</style>